package jdbctest;

import java.sql.*;

/**
 * @author tongchen
 * @create 2022-11-03 16:55
 */
public class JdbcTest5 {
    public static void main(String[] args) throws Exception {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接
        String url="jdbc:mysql://127.0.0.1:3306/exer?useSSL=false";
        String username="root";
        String password="abc123";
        Connection connection = DriverManager.getConnection(url, username, password);
        //3.定义sql语句
        String pwd="1234";
        String name="zhangsan";
        String sql="select *from tb_user where username=? and password =?";
        //4.创建sql对象
        PreparedStatement statement = connection.prepareStatement(sql);
        //4.1替代问号
        statement.setString(1,"zhangsan");
        statement.setString(2,"123");
        //5.执行sql语句
        ResultSet resultSet = statement.executeQuery();
        if(resultSet.next()){
            System.out.println("登录成功");
        }
        else{

            System.out.println("登录失败");
        }

        //7.关闭资源
        resultSet.close();
        statement.close();
        connection.close();


    }
}
